package com.shangxian.giveithome.controller;


import com.shangxian.giveithome.annoaction.CheckLoginStatus;
import com.shangxian.giveithome.code.CheckCode;
import com.shangxian.giveithome.entity.community.Collections;
import com.shangxian.giveithome.mapper.CollectionsMapper;
import com.shangxian.giveithome.mapper.PetMapper;
import com.shangxian.giveithome.result.Result;
import com.shangxian.giveithome.service.ApiService;
import com.shangxian.giveithome.service.CollectionService;
import com.shangxian.giveithome.utils.SenInfoCheckUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/collection")
public class CollectionController {

    @Autowired
    private ApiService apiService;

    @Autowired
    private CollectionService collectionService;

    @Resource
    private PetMapper petMapper;

    @Autowired
    private CollectionsMapper collectionsMapper;


    @GetMapping("/findCollectionsList")
    @ApiOperation(value = "查询合集列表")
    public Result findCollectionsList(@PageableDefault(page = 0, size = 10) Pageable pageable, HttpServletRequest request, @RequestParam(required = false, value = "id") Long id) {
        return Result.success(collectionService.findCollectionsList(pageable, request, id));
    }

    //
    @GetMapping("/findAttentionUserCollectionsListDetails")
    @ApiOperation(value = "查询用户合集列表详情")
    public Result findAttentionUserCollectionsListDetails(@PageableDefault(page = 0, size = 10) Pageable pageable, @RequestParam(value = "id") Long id) {
        return Result.success(collectionService.findUserCollectionsListDetails(pageable, id));
    }

    @PostMapping("/addCollection")
    @ApiOperation(value = "添加合集")
    public Result addCollection(@RequestBody Collections collections, HttpServletRequest request) {
        String access_token = apiService.getAccessToken();
        Boolean aBoolean = SenInfoCheckUtil.cotentFilter(access_token, collections.getCollectionName());
        if (!aBoolean) {
            return Result.error(CheckCode.Content_NOT_Illegal);
        }
        collectionService.addCollection(collections, request);
        return Result.success();
    }

    @PostMapping("/addAdoptCollection")
    @ApiOperation(value = "添加领养合集")
    @CheckLoginStatus
    public Result addAdoptCollection(@RequestParam("id") Long id,HttpServletRequest request){
        return Result.success(collectionService.addAdoptCollection(id,request));
    }


}
